#include <QPainter>
#include <QPolygon>
#include <QDebug>
#include "button.h"


Button::Button(QWidget *parent) :
        QPushButton(parent), drawItem(Empty)
{
    setMinimumSize(QSize(100,100));
    setMaximumSize(QSize(200,200));

    connect(this, SIGNAL(clicked()), this, SLOT(click()));
}


void Button::setDrawItem(DrawItem d)
{
    drawItem = d;
    emit update();
}

Button::DrawItem Button::getDrawItem()const
{
    return drawItem;
}

void Button::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setBrush(Qt::red);
    QPolygon square(rect());
    painter.drawPolygon(square);

    switch(drawItem)
    {
    case Empty:
        break;
    case Cross:
        painter.setBrush(Qt::blue);
        painter.drawLine(0, 0, this -> rect().width(), this -> rect().height());
        painter.drawLine(this -> rect().width(), 0, 0, this -> rect().height());
        break;
    case Nought:
        painter.setBrush(Qt::blue);
        painter.drawArc(this -> rect(), 0,  (16 * 360));
        break;
    }
}

void Button::click()
{
    emit buttonClick(this);
    emit stateChanged();
}
